﻿using MediatR;
using T.Settlement.API.Application.Command.ExpensesCommand;
using T.Settlement.Repository.SettlementInterface;

namespace T.Settlement.API.Application.CommandHandlers.ExpensesHandler
{
    public class ExpensesBatchDelCommandHandler : IRequestHandler<ExpensesBatchDelCommand, int>
    {
        private readonly IExpensesSRepository _repository;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="repository"></param>
        public ExpensesBatchDelCommandHandler(IExpensesSRepository repository)
        {
            _repository = repository;
        }
        public async Task<int> Handle(ExpensesBatchDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _repository.GetAllAsync();
            var elist=list.Where(x=>request.ExpensesId.Contains(x.ExpensesId.ToString())).ToList();
            foreach (var item in elist)
            {
                item.IsDeleted = true;
            }
            return await _repository.UpdateRange(elist);
        }
    }
}
